package com.hxf.dao;

import java.io.Serializable;
import java.util.List; 

import com.hxf.dto.BaseDto;  
import com.hxf.dto.ReturnData;
import com.hxf.dto.TmpTableDto;
import com.hxf.exception.DaoLevelException;

/**
 * DAO公共接口
 * @author tengyicheng
 * @version [1.0, 2013/09/22]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public interface BaseDao<T> {
	/**
	 * 刷新
	 * @throws DaoLevelException
	 */
	public void flush() throws DaoLevelException;

	/**
	 * 保存信息
	 * @param entity
	 * @throws DaoLevelException
	 */
	public void create(BaseDto entity) throws DaoLevelException;
	
	/**
	 * 更新信息
	 * @param entity
	 * @throws DaoLevelException
	 */
	public void update(BaseDto entity) throws DaoLevelException;

	/**
	 * 保存或者修改信息
	 * @param entity
	 * @throws DaoLevelException
	 */
	public void saveOrUpdate(BaseDto entity) throws DaoLevelException;

	/**
	 * 删除信息
	 * @param entity
	 * @throws DaoLevelException
	 */
	public void delete(BaseDto entity) throws DaoLevelException;

	/**
	 * 根据ID 查询信息
	 * @param clazz
	 * @param id
	 * @return
	 * @throws DaoLevelException
	 */
	public BaseDto load(Class clazz, Serializable id) throws DaoLevelException;
	
	/**
	 * HQL查询
	 * @param query
	 * @return
	 * @throws DaoLevelException
	 */
	public List<T> findBy(String hql) throws DaoLevelException;
	
	/**
	 * HQL查询分页
	 * @param query
	 * @return
	 * @throws DaoLevelException
	 */
	public ReturnData<T> findBy(final String hql, final Integer targetPage, final Integer pageSize) throws DaoLevelException;
	
	/**
	 * 根据ID 查询信息
	 * @param clazz
	 * @param id
	 * @return
	 * @throws DaoLevelException
	 */
	public BaseDto get(Class clazz, Serializable id) throws DaoLevelException;
	 
	
	/**
	 * 查询最大ID
	 * @param idName id名
	 * @param tableName 表名
	 * @return Integer
	 */
	public Integer getMaxId(String idName, String className)throws DaoLevelException;
	
	/**
	 * 执行sql
	 * @param sql
	 * @return
	 * @throws DaoLevelException
	 */
	public List exeSQLList(String sql)throws DaoLevelException;
	
	/**
	 * SQL查询分页
	 * @param hql
	 * @param targetPage
	 * @param pageSize
	 * @return
	 * @throws DaoLevelException
	 */
	public ReturnData exeSQLList(final String sql, final Integer targetPage, final Integer pageSize) throws DaoLevelException;
	
	/**
	 * 批量处理HQL
	 * @param hql
	 * @return
	 * @throws DaoLevelException
	 */
	public int executeUpdateByHql(String hql)throws DaoLevelException;
	
	/**
	 * 执行HQL 
	 * @param hql
	 * @return
	 * @throws DaoLevelException
	 */
	public List exeHql(String hql)throws DaoLevelException;
	
	/**
	 * 批量处理SQL
	 * @param sql
	 * @return
	 * @throws DaoLevelException
	 */
	public int executeUpdateBySql(String sql) throws DaoLevelException;
	
	/**
	 * 查询总行数
	 * @param queryStr
	 * @return
	 */
	public int getCount(String queryStr)throws DaoLevelException;
	
	/**
	 * 查询记录总行数
	 * @param queryStr
	 * @return
	 * @throws DaoLevelException
	 */
	public int getRecordCount(String queryStr)throws DaoLevelException;
	
	/**
	 * 查询总行数
	 * @param queryStr
	 * @return
	 */
	public int getCountSQL(String queryStr)throws DaoLevelException;
	
	/**
	 * 查询记录总行数
	 * @param queryStr
	 * @return
	 * @throws DaoLevelException
	 */
	public int getRecordCountSQL(String queryStr)throws DaoLevelException;

	/**
	 * 保存到临时表
	 * @param tmpList
	 * @return
	 * @throws DaoLevelException
	 */
	public int saveTmpTable(List<TmpTableDto> tmpList) throws DaoLevelException;
	
	/**
	 * 删除临时表
	 * @return
	 * @throws DaoLevelException
	 */
	public int deleteTmpTable() throws DaoLevelException;
}
